﻿using Abp.Domain.Repositories;
using Abp.EntityFrameworkCore.Repositories;
using EFCore.BulkExtensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality
{
   public class CeshiAppService :  QualityAppServiceBase
    {
        private readonly IRepository<ceshi,Guid> _articleRepository;
       // private readonly IDapperRepository<ceshi> _ceshiDapper;
        public CeshiAppService(
       //IDapperRepository<ceshi> ceshiDapper
       IRepository<ceshi,Guid> articleRepository
            )
        {
            _articleRepository = articleRepository;
           // _ceshiDapper = ceshiDapper;
        }
        public string GetDapper() 
        {
            //List<ceshi> ceshis =  _ceshiDapper.Query("select * from ceshi").ToList();
            Stopwatch watch = new Stopwatch();
            watch.Start();
            List<ceshi> ceshis = new List<ceshi>();
            for (int i = 0; i < 2000; i++)
            {
                var entity = new ceshi();
                entity.Id = Guid.NewGuid();
                entity.name = $"BulkInsert娱乐";
                ceshis.Add(entity);
            }
            _articleRepository.GetDbContext().BulkInsert(ceshis);
            watch.Stop();
            string time = watch.ElapsedMilliseconds.ToString();
            return time;
        }
            /// <summary>
        /// 批量修改
        /// </summary>
        /// <returns></returns>
        public string BatchUpdate()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            List<ceshi> ceshis = new List<ceshi>();
            List<ceshi> ceshis1 = _articleRepository.GetAll().ToList();

            for (int i = 0; i < ceshis1.Count; i++)
            {
                ceshis1[i].name = "32423";
              //  entity.Id = ceshis1[i].Id;
              //   entity.name = "111";
            }
            _articleRepository.GetDbContext().BulkUpdate(ceshis1);
           //articleRepository.GetAll().Where(m=>m.Id>100).BatchUpdate(new ceshi { name = "Updated娱乐" });
            watch.Stop();
            string time = watch.ElapsedMilliseconds.ToString();
            return time;
        }
    }
}
